package monkey;

import java.awt.Point;
import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;

import view.Environnement;
import assets.Vision;
import food.Food;

/**
 * 
 * @author Steel Magnolias
 * Nathalie GLAD
 * Ailin MORENO
 * 
 * Type de singe
 *
 */
public class Alpha extends Monkey {

	public Alpha(Vision champVision, int hungry, Point start, Environnement e) {
		super(champVision, hungry, start, e);
		BufferedImage img;
		try {
			img = ImageIO.read(this.getClass().getResource("alfa.png"));
		} catch (IOException ex) {
			ex.printStackTrace();
			img = null;
		}
		this.currentState = Monkey.DOMINANT;
		this.representation = img;
	}

	@Override
	public void cheatingOrEating(int fi) {
		moveTo(e.allFoodList.get(fi).getPosition());
		if (position.equals(e.allFoodList.get(fi).getPosition()))
			eat(fi);
	}

	@Override
	public int lookForFood() {
		for (int i = 0; i < e.allFoodList.size(); i++) {
			Food vf = e.allFoodList.get(i);
			if (vf.getFoodState() == Food.VISIBLE_FOOD) {
				if (getChampVision().getWay() > 0) {
					if (vf.getPosition().x > getChampVision()
							.getStartPoint().x
							&& vf.getPosition().x < getChampVision()
									.getEndPointA().x
							&& vf.getPosition().y < getChampVision()
									.getEndPointA().y
							&& vf.getPosition().y > getChampVision()
									.getEndPointB().y) {
						return i;
					}
				} else {
					if (vf.getPosition().x < getChampVision()
							.getStartPoint().x
							&& vf.getPosition().x > getChampVision()
									.getEndPointA().x
							&& vf.getPosition().y < getChampVision()
									.getEndPointA().y
							&& vf.getPosition().y > getChampVision()
									.getEndPointB().y) {
						return i;
					}
				}
			}
		}
		return -1;
	}

}
